package com.example.myapplication.tack_07;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.tack_07.data.YouDetailsData;
import com.example.myapplication.utils.BannerTool;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class XQActivity extends AppCompatActivity {
    private ViewPager banner;
    private ImageView exit;
    private TextView address;
    private TextView phone;
    private TextView workTime;
    private TextView bedsCountBoy;
    private TextView internalFacilities;
    private TextView specialService;
    private TextView surroundingFacilities;
    private TextView introduce;
    private String id = "10";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_07_x_q);
        init();
        Intent intent = getIntent();
        id = intent.getStringExtra(Common.COMMON);
        details(id);
        exit_();

    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                XQActivity.this.finish();
            }
        });
    }

    private void details( String id) {
        String url = "prod-api/api/youth-inn/youth-inn/"+id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, YouDetailsData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                YouDetailsData datailsData = (YouDetailsData) obj;
                String img  = datailsData.getData().getImageUrls();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        detailsAdpater(datailsData,img);
                    }
                });

            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void detailsAdpater(YouDetailsData datailsData, String img) {
        address.setText("地址："+datailsData.getData().getAddress());
        phone.setText(datailsData.getData().getPhone());
        workTime.setText(datailsData.getData().getWorkTime());
        bedsCountBoy.setText(" 男("+datailsData.getData().getBedsCountBoy()+") "+"女("
                +datailsData.getData().getBedsCountGirl()+")");
        internalFacilities.setText(datailsData.getData().getInternalFacilities());
        specialService.setText(datailsData.getData().getSpecialService());
        surroundingFacilities.setText(datailsData.getData().getSurroundingFacilities());
        introduce.setText("驿站简介:\n\n    "+datailsData.getData().getIntroduce());
        List<String> imageUrlList = datailsData.getData().getImageUrlList();
        BannerTool bannerTool = new BannerTool(XQActivity.this,imageUrlList,banner);
        banner.setAdapter(bannerTool);
    }

    private void init() {
        exit = findViewById(R.id.exit);
        banner = findViewById(R.id.banner);
        address = findViewById(R.id.address);
        phone = findViewById(R.id.phone);

        workTime = findViewById(R.id.workTime);
        bedsCountBoy = findViewById(R.id.bedsCountBoy);
        internalFacilities = findViewById(R.id.internalFacilities);
        specialService = findViewById(R.id.specialService);
        surroundingFacilities = findViewById(R.id.surroundingFacilities);
        introduce = findViewById(R.id.introduce);
    }
}